package com.nhc.model;

import android.content.Context;
import android.content.SharedPreferences;

import zuo.biao.library.util.JSON;

public class TwoPointsFileHandle {

    private static TwoPointsFileHandle instance = new TwoPointsFileHandle();

    public static TwoPointsFileHandle getInstance() {
        return instance;
    }

    public TwoPointsInfo mTwoPI = new TwoPointsInfo();
    public PointAZInfo mPAZ = new PointAZInfo();

    public TwoPointsFileHandle() {

    }

    //倾斜墨卡托投影 设置  --- Two Points／Point AZ
    private String OMERCATOR = "ObliqueMercator";
    private String TWOPOINTS = "TwoPoints";
    private String POINTAZ = "PointAZ";
    private String OMERCATOR_MODE = "Mode";

    public int mode = 0;//0-Point AZ 1-Two Points

    public void save(Context context) {
        if (context == null) {
            return;
        }

        String strTwoPoints = JSON.toJSONString(mTwoPI);
        String strPointAZ = JSON.toJSONString(mPAZ);

        SharedPreferences sp = context.getSharedPreferences(
                OMERCATOR, Context.MODE_PRIVATE);

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(TWOPOINTS, strTwoPoints);
        editor.putString(POINTAZ, strPointAZ);
        editor.putInt(OMERCATOR_MODE, mode);
        editor.commit();
    }

    public void load(Context context) {
        if (context == null) {
            return;
        }

        SharedPreferences sp = context.getSharedPreferences(
                OMERCATOR, Context.MODE_PRIVATE);
        String strTwoPoints = sp.getString(TWOPOINTS, "");
        String strPointAZ = sp.getString(TWOPOINTS, "");
        mode = sp.getInt(OMERCATOR_MODE, 0);

        if (strTwoPoints.length() > 1) {
            try {
                com.alibaba.fastjson.JSONObject data = JSON.parseObject(strTwoPoints);
                if (data != null) {
                    mTwoPI = JSON.parseObject(data, TwoPointsInfo.class);
                }
            } catch (Exception e1) {

            }
        }

        if (strPointAZ.length() > 1) {
            try {
                com.alibaba.fastjson.JSONObject data = JSON.parseObject(strPointAZ);
                if (data != null) {
                    mPAZ = JSON.parseObject(data, PointAZInfo.class);
                }
            } catch (Exception e1) {

            }
        }

    }


}